<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Collection;
use App\Models\Issue;
/**
 *
 */
class CollectionController extends Controller
{
	public function index()
	{
		$currentIssue = Issue::orderBy('volume', 'desc')->orderBy('issue', 'desc')->first();
		$collections = Collection::online()->orderBy('created_at', 'desc')->limit(6)->get();

		return view("collection.index", [
			'collections' => $collections,
			'issue' => $currentIssue
			// 'all_collections' => Collection::online()->orderBy('created_at', 'desc')->get()

		]);
	}

	public function articles($id)
	{
		$collection = Collection::find($id);
		if (!$collection) {
			abort(404, 'Can not find Collection');
		}

		$collection->view_count += 1;
		$collection->save(); 


		$currentIssue = Issue::orderBy('volume', 'desc')->orderBy('issue', 'desc')->first();
		return view('collection.articles', [
			'collection' => $collection,
			'articles' => $collection->articles,
			'issue' => $currentIssue
		]);
	}
}